package com.chb.microservice.provider.hystrix;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cbh.api.model.ApiResult;
import com.chb.microservice.provider.feign.PlatePrefixFeignClient;
import com.chb.microservice.provider.model.PlatePrefix;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class PlatePrefixHystrixWrapped {

	@Autowired
	private PlatePrefixFeignClient platePrefixFeignClient;

	/**
	 * 保存车牌前缀信息
	 * @param product
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<String> save(PlatePrefix ob) {
		return platePrefixFeignClient.save(ob);
	}

	public ApiResult<String> fallBackCall(PlatePrefix ob) {
		return new ApiResult<String>().fail("调用报错");
	}

	/**
	 * 获取全部车牌前缀信息
	 * 
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<List<PlatePrefix>> getAll() {
		return platePrefixFeignClient.getAll();
	}

	public ApiResult<List<PlatePrefix>> fallBackCall() {
		return new ApiResult<List<PlatePrefix>>().fail("调用报错");
	}

	/**
	 * 获取车牌前缀信息
	 * 
	 * @param proId
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
	public ApiResult<PlatePrefix> getOne(String id) {
		return platePrefixFeignClient.getOne(id);
	}

	public ApiResult<PlatePrefix> fallBackCall(String id) {
		return new ApiResult<PlatePrefix>().fail("调用报错");
	}

	/**
	 * 删除车牌前缀信息
	 * 
	 * @param proId
	 * @return
	 */
	@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall1")
	public ApiResult<Boolean> delete(String id) {
		return platePrefixFeignClient.delete(id);
	}

	public ApiResult<Boolean> fallBackCall1(String id) {
		return new ApiResult<Boolean>().fail("调用报错");
	}
}
